package com.lmaye.design.patterns.creation.prototype.deepclone;

import org.junit.Test;

/**
 * -- 客户端测试
 *
 * @author lmay.Zhou
 * @date 2020/11/14 1:17 星期六
 * @qq 379839355
 * @email lmay@lmaye.com
 * @since JDK1.8
 */
public class ClientTest {
    @Test
    public void test() throws Exception {
        Rabbit rabbit = new Rabbit("小灰", new Cat("小白"));
        Rabbit rabbit2 = (Rabbit) rabbit.clone2();
        System.out.println(rabbit.hashCode() + ": " + rabbit);
        System.out.println(rabbit2.hashCode() + ": " + rabbit2);
        // 默认浅拷贝（内部引用对象是同一个引用对象）
        System.out.println("rabbit friend hashCode: " + rabbit.getFriend().hashCode());
        System.out.println("rabbit2 friend hashCode: " + rabbit2.getFriend().hashCode());
    }
}
